☰ See All Chapters |
Selenium relative xpath using starts with function: starts-with()
We use starts-with() function to identify those elements whose text value starts with some specified value.
Syntax:
//tagname[starts-with(text(),'text value of the tag')]
Comparison between contains() and starts-with() functions considering below sample html code
<html> </head> <body> <table align="center" width=90% cellspacing="2" cellpadding="2" > <tr> <td>Row 1 : </td> <td><span>welcome to www.tools4testing.com</span></td> </tr> <tr> <td>Row 2 : </td> <td><span>you are welcome !</span></td> </tr> </table> </body> </html> |
Relative XPath | Matching Element |
xpath=//span[starts-with(text(),'welcome')] | Row 1 Span |
xpath=//span[contains(text(),'welcome')] | Both Row1 and Row 2 Span |
You can write the script and test these using our Test Page


All Chapters